import { TUserInFoResult } from '@/api/sys/type'
import { IUserState } from '@/typings'
import { removeToken, setToken } from '@/utils/cookie'
import { RouteRecordRaw } from 'vue-router'
import { SET_MENU_LIST, SET_TOKEN, SET_USER_INFO } from './actionTypes'

export default {
  [SET_TOKEN](state: IUserState, payload: string): void {
    if (payload) {
      setToken(payload)
    } else {
      state.token = ''
      removeToken()
    }
  },
  [SET_MENU_LIST](state: IUserState, menuList: Array<RouteRecordRaw>): void {
    state.currentRouters = menuList
  },
  [SET_USER_INFO](state: IUserState, userInfo: TUserInFoResult): void {
    state.userInfo = userInfo
  }
}
